﻿#region

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Vin.Extension.LoggerNotify.Logger;
using Vin.Extension.LoggerNotify.Logger.Email;
using Vin.Tool.Core.AssemblyCategory;

#endregion

namespace Vin.Extension.LoggerNotify;

public class ExtensionEntry : IVinExtension
{
    public void AddVinExtension(WebApplicationBuilder builder)
    {
        var loggerProvider = AssemblyTool.GetTypes<ILoggerProvider>();
        builder.Services.AddLogging(b =>
        {
            foreach (var t in loggerProvider)
            {
                // 如果是抽象类或者接口则跳过
                if (t.IsAbstract || t.IsInterface || t.IsGenericType) continue;
                // 如果不是BaseLoggerProvider的子类则跳过
                if (t.BaseType?.GetGenericTypeDefinition() != typeof(BaseLoggerProvider<>)) continue;
                b.AddProvider((ILoggerProvider) Activator.CreateInstance(t)!);
            }
            // b.AddProvider(new EmailLoggerProvider());
        });
    }

    public void AddVinExtension(IServiceCollection services)
    {
    }

    public void UseVinExtension(WebApplication app)
    {
    }
}